package com.mikepenz.app.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mikepenz.app.R;
import com.mikepenz.bean.PayOrderBean;
import com.mikepenz.utils.CookicUntil;
import com.quickdv.until.ViewHolder;

import java.util.List;

/**
 * 充值详情
 * Created by lilongfei on 15/8/11.
 */
public class PayDetailAdapter extends BaseAdapter {

    Context c;
    List<PayOrderBean> data;
    LayoutInflater inflater;

    public PayDetailAdapter(Context c, @NonNull List<PayOrderBean> data){
        this.c =c;
        this.data = data;
        inflater = LayoutInflater.from(c);
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null){
            view = inflater.inflate(R.layout.fragment_pay_detail3,null);
        }
        TextView action = ViewHolder.get(view,R.id.paydetail_action);
        TextView money = ViewHolder.get(view,R.id.paydetail_money);
        TextView path = ViewHolder.get(view,R.id.paydetail_path);
        TextView time = ViewHolder.get(view,R.id.paydetail_time);

        if (data.get(i)!=null){
            PayOrderBean order = data.get(i);
            if(order.getType().equals(CookicUntil.RECHARGE)){
                action.setText(R.string.recharge);
                money.setTextColor(c.getResources().getColor(R.color.red));
                money.setText("\\+" + order.getMoney() + "元");
            }else {
                action.setText(R.string.consumption);
                money.setTextColor(c.getResources().getColor(R.color.green));
                money.setText("\\-" + order.getMoney() + "元");
            }
            if (order.getCreateTime()!=null)
                time.setText(order.getCreateTime());
            if (order.getChannel()!=null)
                path.setText(order.getChannel());

        }
        return view;
    }
}
